package cn.edu.wdu.gaojie.reflection.other;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author gaojie  gao4433@qq.com
 * @Description
 * @date 2021/11/29 14:25
 * @since 1.8
 */
public class PeopleRef {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
        Class<?> A = Class.forName("cn.edu.wdu.gaojie.reflection.other.People");
        Object o = A.newInstance();

        Field age = A.getDeclaredField("age");
        age.setAccessible(true);
        age.set(o,20);

        Method getAge = A.getMethod("getAge");
        Object result = getAge.invoke(o);
        System.out.println(result);
    }
}
